
// 封装请求方法
const request = (obj) =>
{
	
	obj.url = obj.url || ''; // 请求路径
	obj.method = obj.method || 'GET'; //请求方式
	obj.data = obj.data || {}; //请求携带的数据
	obj.header = obj.header || 'application/json'; //请求头信息 content-type
	obj.requestTime = obj.requestTime || 500; //多久时间内完成网络请求，则不显示提示框
	//返回Promise对象
	return new Promise((resolve, reject) =>
	{

		let BASE_URL = 'https://api.mingway.info/ai/'
		uni.request(
		{
			url: BASE_URL + obj.url,
			method: obj.method,
			header: obj.header,
			data: obj.data,
			success: res =>
			{
				resolve(res.data);
			},
			fail: err =>
			{
				uni.showToast(
				{
					duration: 3000,
					title: err,
					icon: 'none'
				})
				reject(err);
			},
			complete: () =>
			{
			
			}
		})
	});
}
const post = (url, data, header) =>
{
	let res = request(
	{
		url,
		data,
		method: 'POST',
		header: header ||
		{
			'Content-Type': 'application/x-www-form-urlencoded'
		}
	})
	return res
}
const get = (url, data,header) =>
{
	let res = request(
	{
		url,
		data,
		header:header ||
		{
			'Content-Type': 'application/json'
		},
		method: 'GET',
	})
	return res
}
export
{
	request,
	get,
	post
};
